package com.sense.kukoo.common.repo

import android.app.Application
import com.sense.kukoo.common.repo.http.KukooHttp
import com.sense.kukoo.common.repo.kv.login.Login
import com.sense.kukoo.common.repo.kv.login.LoginImpl
import com.sense.kukoo.common.repo.kv.login_history.LoginHistory
import com.sense.kukoo.common.repo.kv.login_history.LoginHistoryImpl
import com.sense.kukoo.common.repo.kv.search.SearchHistory
import com.sense.kukoo.common.repo.kv.search.SearchHistoryImpl
import com.sense.kukoo.common.repo.kv.user.User
import com.sense.kukoo.common.repo.kv.user.UserImpl
import com.sense.kukoo.common.repo.kv.KukooKeyValueManager
import com.sense.kukoo.common.repo.kv.book_sequence.BookSequenceImpl
import com.sense.kukoo.common.repo.kv.day_night.DayNightImpl
import com.sense.kukoo.common.repo.kv.playlist.PlayListImpl
import com.sense.kukoo.common.repo.kv.playlist_position.PlaylistPositionImpl
import com.sense.kukoo.common.repo.kv.speed.SpeedImpl
import com.sense.kukoo.common.repo.link.DeepLinkImpl
import com.sense.kukoo.common.repo.sql.KukooSqlManager

//持久化数据封装
object Repo {

    private val TAG: String = javaClass.simpleName

    fun init(app: Application, versionName:String, versionCode:Int, isRelease:Boolean) {
        //
        KukooKeyValueManager.init(app)
        KukooKeyValueManager.setDataVersionAndType(versionCode, isRelease)
        //
        KukooSqlManager.createInstance(app)
    }

    val http: KukooHttp  = KukooHttp

    val searchHistory: SearchHistory by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
        SearchHistoryImpl(KukooKeyValueManager.kukooMmkv())
    }

    val login: Login by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
        LoginImpl(KukooKeyValueManager.kukooMmkv())
    }

    val loginHistory: LoginHistory by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
        LoginHistoryImpl(KukooKeyValueManager.kukooMmkv())
    }

    val user: User by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
        UserImpl(KukooKeyValueManager.kukooMmkv())
    }

    val speed: SpeedImpl by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
        SpeedImpl(KukooKeyValueManager.kukooMmkv())
    }

    val bookSequence: BookSequenceImpl by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
        BookSequenceImpl(KukooKeyValueManager.kukooMmkv())
    }

    val playlist: PlayListImpl by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
        PlayListImpl(KukooKeyValueManager.kukooMmkv())
    }

    val playlistPosition: PlaylistPositionImpl by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
        PlaylistPositionImpl(KukooKeyValueManager.kukooMmkv())
    }

    val dayNightMode: DayNightImpl by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
        DayNightImpl(KukooKeyValueManager.kukooMmkv())
    }

    val link: DeepLinkImpl by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
        DeepLinkImpl()
    }

}